﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace CreditAgricole.TestWorkflow
{
    public sealed partial class Workflow1 : SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

        private void InitializeActivity_ExecuteCode(object sender, EventArgs e)
        {
            Console.WriteLine("IsDynamicActivity : {0}", (sender as CodeActivity).IsDynamicActivity ? "true" : "false");
            Console.WriteLine("Workflow Initialized");
        }

        private void WriteActivity_ExecuteCode(object sender, EventArgs e)
        {
            // Try to access current replicator instance
            //Console.Write(e.ToString());
            CodeActivity ca = sender as CodeActivity;
            Console.WriteLine(ca.UserData);
            Console.WriteLine("IsDynamicActivity : {0}", ca.IsDynamicActivity ? "true" : "false");
            ReplicatorActivity ra = ca.Parent as ReplicatorActivity;
            Console.WriteLine("#" + ra.DynamicActivities.Count.ToString());
            Console.WriteLine("{0} {1}", ra.CurrentIndex.ToString(), ra.Name);
        }

        private void ReplicatorActivity_ChildInitialized(object sender, ReplicatorChildEventArgs e)
        {
            Console.WriteLine("From ChildInitialized {1} : {0}", e.InstanceData.ToString(), e.Activity.Name);
        }

        private void ReplicatorActivity_Initialized(object sender, EventArgs e)
        {
            words = new string[] { "1er élément", "2ème élément", "3ème élément", "4ème élément" };
        }

        public IList words = default(System.Collections.IList);
    }

}
